<?php
declare(strict_types=1);

namespace App\Common\Modular\System\Serve;

use App\Common\Modular\System\Enums\SmsEnums;
use App\Common\Modular\System\Model\SmsTemplateModel;
use Core\Basics\BasicsServe;
use Zms\Unit\Arr;

/**
 * 短信日志
 * @method SmsTemplateModel getModel()
 */
class SmsTemplateServe extends BasicsServe
{
    /**
     * @return SmsTemplateModel::class
     */
    public static function model(): string
    {
        return SmsTemplateModel::class;
    }


    /**
     * 获取短信验证码模板
     * @return array
     */
    public function getSmsTemplateList(): array
    {
        $enums = SmsEnums::Datas();
        $templates = [];
        $TemMap = Arr::map($this->search()->get()->toArray(), 'key', null);
        foreach ($enums as $item) {
            $template = [
                'KEY' => $item['value'],
                'TEMPLATE_ID' => '',
                'DESCRIPTION' => $item['description'],
                'CONTENT' => '',
                'PARAM' => [
                    ['key' => '{signature}', 'value' => '短信签名'],
                    ...$item['param']
                ]
            ];
            $tem = $TemMap[$item['value']] ?? null;
            if ($tem) {
                $template['TEMPLATE_ID'] = $tem['template_id'];
                $template['CONTENT'] = $tem['content'];
            }
            $templates[] = $template;
        }
        return $templates;
    }
}